//这个模块对api进行统一的管理，便于后期接口发生变化时修改
import requests from './request'

import mockRequest from './mockrequest'

//三级联动接口
//对外暴露一个方法
export const reqCategoryList = () => {
    //发请求,将请求结果返回
    return requests({
        url: 'product/getBaseCategoryList',
        method: 'get'
    })
}

//获取banner数据
export const reqBannerList = () => mockRequest.get('/mock/banner')

//获取Flooer组件的数据
export const reqFlooerList = () => mockRequest.get('/mock/floor')

/*
    获取搜索模块数据
给服务器的参数：
{
  "category1Id":""   //一级分类的id
  "category1Id":""   //二级分类的id
  "category3Id": ""  //三级分类的id
  "categoryName":""  //分类名字
  "keyword": ""      //搜索输入的关键字
  "order": "1:desc"  //排序方式
  "pageNo": 1        //分页器用，代表当前几页
  "pageSize": 10     //每一页展示数据个数
  "props": []        //平台售卖属性的操作带的参数
  "trademark": ""    //品牌
}
*/
export const reqGetSearchInfo = (params) => {
    return requests({
        url: '/list',
        method: 'post',
        data: params
    })
}

//获取商品详情
export const reqGoodInfo = (skuId) => requests({ url: `/item/${skuId}`, method: 'get' })

//储存购物车数据 /api/cart/addToCart/{ skuId }/{ skuNum }
export const reqUpdateShopCart = (skuId, skuNum) => requests({ url: `/cart/addToCart/${skuId}/${skuNum}`, method: 'post' })
//获取购物车列表
export const reqShopCartList = () => requests({ url: '/cart/cartList', method: 'get' })
//删除购物车列表操作
export const reqDeleteCart = (skuId) => requests({ url: `/cart/deleteCart/${skuId}`, method: 'delete' })
//修改商品选中状态
export const reqCheckCart = (skuId, isChecked) => requests({ url: `/cart/checkCart/${skuId}/${isChecked}`, method: 'get' })
//获取验证码
export const reqSendCode = (phone) => requests({ url: `/user/passport/sendCode/${phone}`, method: 'get' })
//用户注册
export const reqRegister = (userInfo) => requests({
    url: '/user/passport/register',
    method: 'post',
    data: userInfo
})
//用户登录
export const reqLogin = (data) => requests({ url: '/user/passport/login', data, method: 'post' })

//自动登录，通过token获取用户信息
export const reqUserInfo = () => requests({ url: '/user/passport/auth/getUserInfo', method: 'get' })

//退出登录
export const reqLogout = () => requests({ url: '/user/passport/logout', method: 'get' })

//获取用户地址信息 '/user/userAddress/auth/findUserAddressList'
export const reqAddressList = () => requests({ url: '/user/userAddress/auth/findUserAddressList', method: 'get' })

//获取订单交易页信息
export const reqTrade = () => requests({ url: '/order/auth/trade', method: 'get' })

//提交订单信息
export const reqSubmit = (tradeNo, data) => requests({ url: `/order/auth/submitOrder?tradeNo=${tradeNo}`, data, method: 'post' })

//获取订单支付信息
export const reqPayment = (orderId) => requests({ url: `/payment/weixin/createNative/${orderId}`, method: 'get' })

//查询支付状态
export const reqPayStatus = (orderId) => requests({ url: `/payment/weixin/queryPayStatus/${orderId}`, method: 'get' })

//获取我的订单列表
export const reqMyorderList = (page, limit) => requests({ url:`/order/auth/${page}/${limit}`, method: 'get' })